<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增医院科室')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">科室名称：</label>
            <div class="col-sm-8">
                <input name="deptName" class="form-control" type="text">
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 医院实际科室名称</span>
            </div>
        </div>
        <!--  标准科室代码   -->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">标准科室名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <select name="standardDeptCode" class="form-control m-b"
                            th:with="type=${@dict.getType('yf_standard_dept_code')}">
                        <option value="">--请选择--</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                th:value="${dict.dictValue}"></option>
                    </select>
                </div>
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 全国统一的标准科室名称</span>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">负责人：</label>
            <div class="col-sm-8">
                <input name="deptUserName" class="form-control" type="text" maxlength="10">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">固定电话：</label>
            <div class="col-sm-8">
                <input name="deptTel" class="form-control" type="number" maxlength="12"
                       oninput="if(value.length>12)value=value.slice(0,12)" placeholder="0311887662**">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">负责人电话：</label>
            <div class="col-sm-8">
                <input name="deptIphone" class="form-control" type="text"
                       oninput="if(value.length>11)value=value.slice(0,11)" placeholder="1994****646">
            </div>
        </div>
        <!-- 科室类型 -->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control" minimumResultsForSearch=-1
                        th:with="type=${@dict.getType('HOSP_DEPT_TYPE')}">
                    <option value="">请选择科室</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">医院：</label>
            <div class="col-sm-8">
                <select name="hospitalId" id="hospitalId" class="form-control" data-form="formed"
                        th:with="type=${@dep.getDep()}">
                    <option th:each="dept : ${type}" th:text="${dept.deptName}" th:value="${dept.deptId}"
                            th:selected="${dept.deptId}==${hostId}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">楼号：</label>
            <div class="col-sm-8">
                <input name="buildingNo" class="form-control" value="1" type="number" max="9999" min="0">
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 科室所属楼</span>
            </div>
        </div>
        <!--  分组编号  -->
        <div class="form-group">
            <label class="col-sm-3 control-label">分组编号：</label>
            <div class="col-sm-8">
                <input name="groupNo" class="form-control" type="number" max="999" maxlength='2'
                       oninput='checkNo(this)'>
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 分组编号不填或为1时，分组名称可以不填</span>
            </div>
        </div>
        <!--  分组名称  -->
        <div class="form-group">
            <label class="col-sm-3 control-label">分组名称：</label>
            <div class="col-sm-8">
                <input name="groupName" class="form-control" maxlength="30">
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 分组编号不是1时，请填写分组名称</span>
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 分组编号一致的科室，请保持分组名称一致</span>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" maxlength="400" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">

    var prefix = ctx + "yf/dept";
    $("#form-dept-add").validate({
        focusCleanup: true,
        rules: {
            deptName: "required",
            standardDeptCode: "required",
            deptUserName: "required",
            type: "required",
            deptTel: {
                // pattern: /(^(\d{3,4}-)?\d{6,8}$)|(^(\d{3,4}-)?\d{6,8}(-\d{1,5})?$)|(\d{11})/
                deptTel: true
            },
            deptIphone: {
                isPhone: true
            },
            hospitalId: "required",
            buildingNo: "required"

        },
        messages: {
            deptName: "科室名称不能为空",
            standardDeptCode: "标准科室名称不能为空",
            deptUserName: "负责人姓名不能为空"
        }
    });
    // 固定电话验证
    $.validator.addMethod("deptTel", function (value, element) {
        var tel = /(^(\d{3,4})?\d{6,8}$)/;
        return this.optional(element) || (tel.test(value));
    }, "请正确填写电话");


    // $.validator.addMethod("depttype", function (value, element) {
    //     return this.optional(element) || (value > 0);
    // })

    // 分组编号不能大于2位
    function checkNo(no) {
        if (no.value.length > 2) {
            no.value = no.value.slice(0, 2);
        }
        if (no.value == 0) {
            no.value = '';
        }
    }


    function submitHandler() {
        if ($.validate.form()) {
            var groupNo = $('input[name="groupNo"]').val();
            var groupName = $('input[name="groupName"]').val();
            if (groupNo != null && groupNo != '' && groupNo != 1) {
                if (groupName == null || groupName == '') {
                    $.modal.alertWarning("分组编号不是1时，请填写分组名称");
                    return;
                }
            } else if (groupNo == null || groupNo == '') {   // 分组编号不填，分组名称也不需要填
                if (groupName != null && groupName != '') {
                    $.modal.alertWarning("分组编号不填，分组名称也不需要填");
                    return;
                }
            }

            $.operate.save(prefix + "/add", $('#form-dept-add').serialize() + "&" + $.param({"hospitalId": $("#hospitalId").val()}));
        }
    }
</script>
</body>
</html>